#include <iostream>

/**
 * @brief 本程序使用c++11编写请注意使用c++11开关
 */
using namespace std;

const string DELETE_SUCCESS = "已经删除";
const string DELETE_FAILURE = "链表中没有此结点，无法删除";
const string NOT_FOUND = "找不到此结点";

// 链表结构
struct node
{
    int data;
    node *next;
};

class LinkedList
{

public:
    node *head;
    node *tail;
    LinkedList()
    {
        head = nullptr;
        tail = nullptr;
    }

    ~LinkedList() {
        node *temp = new node;
        node *cur = nullptr;
        temp = head;
        while (temp != nullptr)
        {
            cur = temp;
            if (cur) {
                delete cur;
            }
            temp = temp->next;
        }
        head = tail = nullptr;
    }

    // 判空
    bool empty()
    {
        return head == nullptr;
    }

    // 输出结果
    void print()
    {
        cout << "==输出链表==" << endl;
        node *temp = new node;
        temp = head;
        cout << "[";
        while (temp != nullptr)
        {
            cout << temp->data;
            temp = temp->next;
            if (temp)
            {
                cout << ",";
            }
        }
        cout << "]" << endl;
        cout << "==结束输出==" << endl;
    }

    // 新增结点
    void appendNode(const int value)
    {
        node *temp = new node;
        temp->data = value;
        temp->next = nullptr;

        if (this->empty())
        {
            head = temp;
            tail = temp;
            temp = nullptr;
        }
        else
        {
            tail->next = temp;
            tail = temp;
        }
    }

    // 查询结点
    void findNode(const int value) {
        node *current = new node;
        node *previous = new node;

        bool foundValue = false;
        unsigned int counter = 0;

        current = head;
        while (current != nullptr)
        {
            ++counter;
            if (current->data == value)
            {
                foundValue = true;
                previous->next = current->next;
                break;
            }
            previous = current;
            current = current->next;
        }

        if (foundValue) {
            cout << "这个结点是第 " << counter << " 个结点。" << endl;
        } else {
            cout << NOT_FOUND << endl;
        }
    }

    // 删除结点
    void deleteNode(const int value)
    {
        node *current = new node;
        node *previous = new node;

        bool foundValue = false;

        current = head;
        while (current != nullptr)
        {
            if (current->data == value)
            {
                foundValue = true;
                previous->next = current->next;
                if (current == head)
                {
                    head = previous->next;
                }
                delete current;
                break;
            }
            previous = current;
            current = current->next;
        }

        if (foundValue) {
            cout << DELETE_SUCCESS << endl;
        } else {
            cout << DELETE_FAILURE << endl;
        }
    }

    void unique()
    {
        node *ptr1, *ptr2, *dup;
        ptr1 = head;

        /* 选取元素 */
        while (ptr1 != NULL && ptr1->next != NULL)
        {
            ptr2 = ptr1;

            /* 将选取的元素与其余元素进行比较元素的 */
            while (ptr2->next != NULL)
            {
                /* 如果重复，则删除它 */
                if (ptr1->data == ptr2->next->data)
                {
                    ptr2->next = ptr2->next->next;
                    delete (dup);
                } else {
                    ptr2 = ptr2->next;
                }
            }
            ptr1 = ptr1->next;
        }
    }
};

int main(int argc, char *argv[])
{
    LinkedList *table = nullptr;
    int number = -1;
    while (cin >> number && number > 0)
    {
        if (table == nullptr)
        {
            table = new LinkedList;
        }
        table->appendNode(number);
    }
    if (table) {
        table->print();
    }
    // table = new LinkedList;
    // if (table)
    // {
    //     table->appendNode(1);
    //     table->appendNode(12);
    //     table->appendNode(123);
    //     table->appendNode(1);
    //     table->appendNode(12);
    //     table->appendNode(123);
    //     table->appendNode(1);
    //     table->appendNode(12);
    //     table->appendNode(123);
    //     table->unique();
    //     table->print();
    //     table->deleteNode(1293);
    //     table->print();
    //     table->findNode(123);
    // }
    return 0;
}